#coding=utf-8
import uliweb.form as form
from uliweb.form import *
from uliweb.form.layout import QueryLayout
from uliweb.i18n import gettext_lazy as _

class QueryForm(form.Form):
    form_buttons = form.Submit(value=_('Search'), _class=".submit")
    layout_class = QueryLayout
    form_method = 'GET'
    
    def post_html(self):
        buf = """
<script>
$(document).ready(function(){
    $('#query_div').hide();
    $('#more_query').click(function(){
        $('#query_div').toggle();
    });
});
</script>
    """
        return buf

class QueryAssignmentForm(QueryForm):
    
    def post_html(self):
        from uliweb.core.js import json_dumps
        from uliweb import settings

        buf = """
<script>
$(document).ready(function(){
    $('#query_div').hide();
    $('#more_query').click(function(){
        $('#query_div').toggle();
    });
});
</script>
    
<script>
    jQuery.fn.extend({
        selectLink:function(ids,id,JSON){
            $(ids).change(function(){
                var b = [];html = '<option value=""></option>';
                $(id).html(html);
                var c = $(ids).val();
                b = JSON[c];
                if(b != ''){
                    for(var j in b){html = html + '<option value=' + b[j][0] + '>' + b[j][1] + '</option>'}
                    $(id).html(html);
                }
            })
        }
    }); 
    //js页面
    $(document).ready(function(){
        $().selectLink('#field_type','#field_stage',stage)
    });
    var stage = %s;
</script>
""" % json_dumps(settings.PARA.ASSIGNMENT_STAGE)
        return buf

class QueryRequirementForm(QueryForm):
    
    def post_html(self):
        from uliweb.core.js import json_dumps
        from uliweb import settings

        buf = """
<script>
$(document).ready(function(){
    $('#query_div').hide();
    $('#more_query').click(function(){
        $('#query_div').toggle();
    });
});
</script>
    
<script>
    jQuery.fn.extend({
        selectLink:function(ids,id,JSON){
            $(ids).change(function(){
                var b = [];html = '<option value=""></option>';
                $(id).html(html);
                var c = $(ids).val();
                b = JSON[c];
                if(b != ''){
                    for(var j in b){html = html + '<option value=' + b[j][0] + '>' + b[j][1] + '</option>'}
                    $(id).html(html);
                }
            })
        }
    }); 
    //js页面
    $(document).ready(function(){
        $().selectLink('#field_mode','#field_stage',stage)
    });
    var stage = %s;
</script>
""" % json_dumps(settings.PARA.REQ_STAGE)
        return buf

class QueryTaskForm(form.Form):
    form_buttons = form.Submit(value=_('Search'), _class=".submit")
    layout_class = QueryLayout
    form_method = 'GET'
    
    def post_html(self):
        buf = """
<script>
$(document).ready(function(){
    $('#query_div').hide();
    $('#more_query').click(function(){
        $('#query_div').toggle();
    });
});
</script>
    """
        return buf
